<?php
error_reporting("E_ALL");ini_set("display_errors", 1);
$getdata=$_REQUEST;
if(empty($getdata))$getdata=$_POST?$_POST:$_GET;
$type=empty($getdata['type'])?'':$getdata['type'];
include("include/function.php");
//header("content-Type: application/json; charset=utf-8");
$config = include("config.php");
include("include/".$config['DB_TYPE'].".class.php");
$db = new db;
$db->connect($config['DB_HOST'],$config['DB_USER'],$config['DB_PWD'],$config['DB_NAME'], $config['DB_PCONNECT']);
  
$page = empty($getdata['page'])?1:$getdata['page'];
$id = empty($getdata['id'])?0:$getdata['id'];
$length=10;
$start=($page-1)*$length;
$end =$start+$length;
$totalpage=4322;
$post=[];
$post['draw']='2';
$post['start']=$start;
$post['length']=$length;
$post['token']='cbaa7eacc53a46d0ac941dc7aa926f8e.SC_EDU_WEB';
$post['unitUuid']='a9ff0204feea4e1d9e63a94e456df184';
$post['parUuid']='';
$post['batchNum']='202502';
$post['schoolUuid']='';
$post['classUuid']='';
$post['personType']=0;
$post['payed']='2';
$post['studentName']='';
$post['classType']='';
$post['cfType']='';
$url='https://hdzycf.xyt360.com.cn/kitchen/web/fee/getOrderListByRecord';
$result = http_post($url,http_build_query($post),array('Content-Type: application/x-www-form-urlencoded'),'rmbUser=true; userName=admink');
$content=json_decode($result,1);$insert=0;
if(!empty($content['data'])){
    foreach($content['data'] as $k=>$v){
        $check = $db->get_one("select `id` from order_info where `id`='".$v['id']."'");
        if(empty($check)){unset($v['unitId']);
            $v['studentName']=str_replace("'","",$v['studentName']);
            $sql = "insert into order_info(`".implode('`,`',array_keys($v))."`) values('".implode("','",$v)."');";
            $res = $db->query($sql);
            if(!$res)exit;$insert++;
        }
        echo $v['id'].'=>'.$v['studentName']."\n<br>";
    }
    $page++;
}else{print_r($content);
    $id++;sleep(3);
}
if($page>=$totalpage){echo 'over';exit;}
$log = $id.'导入成功,新增：'.$insert.'条';
echo $log.'<script>location.href="?page='.$page.'&id='.$id.'";</script>';

//echo count($sqlarr)."\n";
//echo implode(";\n",$sqlarr);
?>